package zhongbo.java.websocket.demo.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import zhongbo.java.websocket.demo.dto.ResultDto;
import zhongbo.java.websocket.demo.dto.TopMessageDto;
import zhongbo.java.websocket.demo.service.IMessageRankService;
import zhongbo.java.websocket.demo.service.IOnlineUserService;

import java.util.List;
import java.util.Set;

/**
 * 说明：
 *
 * @author 钟波dellNotebook
 * @since 2025年03月24日 星期一 04:22:46
 */
@RestController
@Controller
@RequestMapping("/chatApi")
@Api(value = "聊天室相关接口", tags = {"聊天室相关接口"})
public class ChatController {

    @Autowired
    private IOnlineUserService onlineUserService;

    @Autowired
    private IMessageRankService messageRankService;

    @ResponseBody
    @GetMapping(value = "/getOnlineUsers", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取在线用户接口")
    public ResultDto<Set<String>> getOnlineUsers() {
        Set<String> onlineUsers = onlineUserService.getOnlineUsers();
        return ResultDto.ok(onlineUsers);
    }

    @ResponseBody
    @GetMapping(value = "/getTopUserMessage", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "获取消息排行榜接口")
    public ResultDto<List<TopMessageDto>> getTopUserMessage() {
        List<TopMessageDto> userMessage = messageRankService.getTopUserMessage();

        return ResultDto.ok(userMessage);
    }
}
